package com.cyf.mq.consumer.multi;

import com.cyf.mq.common.constant.MQConstant;
import com.cyf.mq.common.pojo.HeroDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Component;

/**
 * @author chenyifan
 * @create 2025-02-21 10:23
 */
@Component
@RocketMQMessageListener(
        consumerGroup = MQConstant.MESSAGE_CONSUMER_GROUP_MULTI,
        topic = MQConstant.MESSAGE_TOPIC_KING_MULTI,
        messageModel = MessageModel.BROADCASTING
)
@Slf4j
public class Consumer1 implements RocketMQListener<HeroDTO>, RocketMQPushConsumerLifecycleListener {

    @Override
    public void onMessage(HeroDTO body) {
        log.info("Consumer1 接收到消息: {}", body);
    }

    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {
        consumer.setInstanceName("multi-consumer-1");
    }
}
